package leetcode.median;
/**
 * @author liyifan
 * @desc 对比版本号
 * @date 10:00 2022/7/31
 **/
public class $165_CompareVersion {
    public int compareVersion(String version1, String version2) {
        int n = version1.length();
        int m = version2.length();
        int i = 0;
        int j = 0;
        while (i < n || j < m) {
            int a = 0;
            int b = 0;
            while (i < n  && version1.charAt(i) != '.') {
                a = a * 10 + version1.charAt(i) - '0';
                i++;
            }
            i++;
            while (j < m  && version2.charAt(j) != '.') {
                b = b * 10 + version2.charAt(j) - '0';
                j++;
            }
            j++;

            if (a > b) {
                return 1;
            } else if (a < b) {
                return -1;
            }
        }
        return 0;
    }
}
